home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / File / Disk Catalog < prev    next >
Encoding:
Text File  |  1999-03-04  |  3.7 KB  |  166 lines  |  [TEXT/ToyS]

  1. property kasMaxDepth : 1 -- Maximum folders to follow down
  2. property kasGoDeepOnCaps : true -- Go deeper if folder is all caps
  3. property kasBlankAfter : 40
  4.  
  5.  
  6. on run
  7.     open {choose folder with prompt "Choose a folder or volume to catalog…"}
  8. end run
  9.  
  10.  
  11. on open fsObjs
  12.     repeat with fsObj in fsObjs
  13.         CreateCatalog(fsObj)
  14.     end repeat
  15. end open
  16.  
  17.  
  18. property sLastLocation : {40, 60}
  19.  
  20. global gasTitle
  21. global gasTotal
  22. global gasList
  23. global gasDone
  24. global gasColumn
  25.  
  26. on CreateCatalog(fsObj)
  27.     set progW to display progress titled ¬
  28.         "Cataloging Disk" subtitled ¬
  29.         "Scanning…" maximum 1 located at sLastLocation
  30.     
  31.     set gasDone to 0
  32.     set gasColumn to 0
  33.     set gasTotal to 0
  34.     set gasList to {}
  35.     
  36.     set info to basic info for fsObj
  37.     set gasTitle to catalog name of info
  38.     
  39.     if (the catalog kind of info is a folder) then
  40.         set gasList to AddFolder(progW, 0, fsObj)
  41.         CreateCatalogList(progW)
  42.     end if
  43.     
  44.     set sLastLocation to screen location of (display progress progW)
  45.     display progress progW with disposal
  46. end CreateCatalog
  47.  
  48.  
  49. on AddFolder(progW, depth, fsObj)
  50.     set myList to {}
  51.     set myFiles to {}
  52.     set myFolders to {}
  53.     
  54.     set info to basic info for fsObj
  55.     set dad to fsObj as string
  56.     set cont to list folder fsObj
  57.     
  58.     display progress progW labeled (catalog name of info)
  59.     
  60.     repeat with f in cont
  61.         set subObj to (dad & f) as alias
  62.         set subInfo to basic info for subObj
  63.         if (catalog kind of subInfo is a folder) and ¬
  64.             ((depth < kasMaxDepth) or ¬
  65.                 (kasGoDeepOnCaps and IsCaps(f))) then
  66.             set myFolders to myFolders & f
  67.         else
  68.             set myFiles to myFiles & f
  69.         end if
  70.     end repeat
  71.     
  72.     set gasTotal to gasTotal + 1 + (number of items of myFiles)
  73.     set myList to {":" & (catalog name of info), myFiles, AddFolders(progW, dad, depth + 1, myFolders)}
  74.     
  75.     return myList
  76. end AddFolder
  77.  
  78.  
  79. on AddFolders(progW, dad, depth, subfolders)
  80.     set myList to {}
  81.     
  82.     repeat with f in subfolders
  83.         set myList to myList & {AddFolder(progW, depth, (dad & f) as alias)}
  84.     end repeat
  85.     
  86.     return myList
  87. end AddFolders
  88.  
  89.  
  90. on CreateCatalogList(progW)
  91.     display progress progW subtitled "Listing…" maximum gasTotal
  92.     
  93.     tell application "Tex-Edit Plus" to ¬
  94.         set name of (make new window) to gasTitle
  95.     
  96.     repeat with f in gasList
  97.         ListOne(progW, 0, f)
  98.     end repeat
  99.     
  100.     tell window gasTitle of application "Tex-Edit Plus"
  101.         delete character 1 -- first return
  102.         set style of line 1 to bold
  103.     end tell
  104. end CreateCatalogList
  105.  
  106.  
  107. on ListOne(progW, depth, fList)
  108.     if (class of fList is list) then
  109.         repeat with f in fList
  110.             if (class of f is list) then
  111.                 ListOne(progW, depth + 1, f)
  112.             else
  113.                 AddLine(progW, depth, f)
  114.             end if
  115.         end repeat
  116.     else
  117.         AddLine(progW, depth, fList)
  118.     end if
  119. end ListOne
  120.  
  121.  
  122. on AddLine(progW, depth, txt)
  123.     set isFolder to (first character of txt is ":")
  124.     if isFolder then set txt to "◊ " & (text from character 2 to -1 of txt)
  125.     
  126.     if (depth > 1) then
  127.         repeat with i from 2 to depth
  128.             set txt to tab & txt
  129.         end repeat
  130.     end if
  131.     
  132.     tell window gasTitle of application "Tex-Edit Plus"
  133.         copy return & txt to after last line
  134.         
  135.         if (not isFolder) then set depth to -1
  136.         
  137.         set color of last line to item (2 + depth) of ¬
  138.             {black, blue, blue, red, magenta, green, cyan, yellow}
  139.     end tell
  140.     
  141.     set gasColumn to gasColumn + 1
  142.     set gasDone to gasDone + 1
  143.     
  144.     if (gasColumn is kasBlankAfter) then
  145.         tell window gasTitle of application "Tex-Edit Plus" to copy return to after last line
  146.         set gasColumn to 0
  147.     end if
  148.     
  149.     display progress progW value 0
  150. end AddLine
  151.  
  152.  
  153. property sLowA : ASCII number "a"
  154. property sLowZ : ASCII number "z"
  155. property sAsc0 : ASCII number "0"
  156. property sAsc9 : ASCII number "9"
  157.  
  158. on IsCaps(s)
  159.     repeat with c in characters of s
  160.         set n to ASCII number c
  161.         if (n ≥ sLowA) and (n ≤ sLowZ) then return false
  162.         if (n ≥ sAsc0) and (n ≤ sAsc9) then return false
  163.     end repeat
  164.     return true
  165. end IsCaps
  166.